<template>
    <div>
        <van-search v-model="value" show-action placeholder="请输入搜索关键词" @update:model-value="inputs">
            <template #left>
                <div @click="proxy.$leftClick" class="qu">取消</div>
            </template>
            <template #action>
                <div @click="founds">搜索</div>
            </template>
        </van-search>
        <van-list >
            <van-cell v-for="item in store.foundData" :key="item.proid"  @click="lis(item.proid)">
                <template #default>
                    <div class="lisSpan">
                        {{ item.proname }}
                        <br>
                        <van-tag plain type="danger" v-if="item.isseckill==1">秒杀</van-tag>
                        <van-tag plain type="danger" v-if="item.discount<3">{{ item.discount }}折</van-tag>
                        <van-tag plain type="warning" v-else-if="item.discount<7.5">{{ item.discount }}折</van-tag>
                        <van-tag plain type="primary" v-else-if="item.discount<10">{{ item.discount }}折</van-tag>
                    </div>
                </template>
            </van-cell>
        </van-list>
    </div>
</template>

<script setup lang="ts">
import { getCurrentInstance, ref,onBeforeMount,onUnmounted} from 'vue';
import { useRouter } from 'vue-router';
import _ from 'lodash'
import { usefound } from '../store/found'
import { usefounded } from '@/store/founded';
const founded = usefounded();
const { proxy }: any = getCurrentInstance();
const store = usefound();
const router = useRouter()
let value = ref('');
let changeData = _.debounce(store.fetchGetFoundData,400);
let inputs = () => {
    console.log(value.value);
    
    changeData(value.value);
}

let lis = (id:string)=>{
    router.push(`/detail/${id}`)
}

const founds = ()=>{
    founded.inputs = value.value;
    router.push({name:"founded"})
}
onUnmounted(()=>{
    value.value = '';
    changeData(value.value);
})
</script>

<style lang="scss">
.qu {
    font-size: 3.73333vw;
    margin-right: 10px;
}
.lisSpan{
    text-align: left;
    .van-tag{
        margin: 0 10px;
    }
}
</style> 